/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package org.kunteng.yunac.modules.sys.entity;

import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.kunteng.yunac.common.config.Global;
import org.kunteng.yunac.common.persistence.DataEntity;
import org.kunteng.yunac.common.supcan.annotation.treelist.cols.SupCol;


/**
 * 用户Entity
 * @author ThinkGem
 * @version 2013-12-05
 */
public class User extends DataEntity<User> {

	private static final long serialVersionUID = 1L;
	private String account;// 登录名
	private String passwd;// 密码
	private String name;	// 渠道商名、商家名
	private String tel;	// 联系电话
	private String type;// 用户类型
	private String loginFlag;	// 是否允许登陆
	private String avatar;	// 头像
	private String logo; // 用户Logo
        private String addr;
	private String province;
	private String city;
	private String area;
        private String code;  // 用户上级Code
        private String category; // 行业
	private int weight; // 权值
	private User parent; // 父渠道商

	private String oldLoginName;// 原登录名
	private String newPassword;	// 新密码

	public User() {
		super();
		this.loginFlag = Global.YES;
	}
	
	public User(String id){
		super(id);
	}

	public User(String id, String loginName){
		super(id);
		this.account = loginName;
	}
	
	public String getAvatar() {
		return avatar;
	}

	public void setAvatar(String photo) {
		this.avatar = photo;
	}

	public String getLoginFlag() {
		return loginFlag;
	}

	public void setLoginFlag(String loginFlag) {
		this.loginFlag = loginFlag;
	}

	@SupCol(isUnique="true", isHide="true")
	public String getId() {
		return id;
	}

	@Length(min=1, max=100, message="登录名长度必须介于 1 和 100 之间")
	public String getAccount() {
		return account;
	}

	public void setAccount(String loginName) {
		this.account = loginName;
	}

	@JsonIgnore
	@Length(min=1, max=100, message="密码长度必须介于 1 和 100 之间")
	public String getPasswd() {
		return passwd;
	}

	public void setPasswd(String password) {
		this.passwd = password;
	}

	@Length(min=1, max=100, message="姓名长度必须介于 1 和 100 之间")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Length(min=0, max=200, message="电话长度必须介于 1 和 200 之间")
	public String getTel() {
		return tel;
	}

	public void setTel(String phone) {
		this.tel = phone;
	}

	public String getRemarks() {
		return remarks;
	}
	
	@Length(min=0, max=100, message="用户类型长度必须介于 1 和 100 之间")
	public String getType() {
		return type;
	}

	public void setType(String userType) {
		this.type = userType;
	}

	public String getOldLoginName() {
		return oldLoginName;
	}

	public void setOldLoginName(String oldLoginName) {
		this.oldLoginName = oldLoginName;
	}

	public String getNewPassword() {
		return newPassword;
	}

	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public User getParent() {
        return parent;
    }

    public void setParent(User parent) {
        this.parent = parent;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

	/**
	 * 用户拥有的角色名称字符串, 多个角色名称用','分隔.
	 */
//	public String getRoleNames() {
//		return Collections3.extractToString(roleList, "name", ",");
//	}
	
	public boolean isAdmin(){
		return isAdmin(this.id);
	}
	
	public static boolean isAdmin(String id){
		return id != null && "1".equals(id);
	}
	
	@Override
	public String toString() {
		return id;
	}

	public static final String CHANNEL_TYPE = "0";
	public static final String MERCHANT_TYPE = "1";
}